package com.xy.controller.order;

import com.xy.api.model.dto.mainData.ProductTreeNodeDTO;
import com.xy.api.model.dto.order.PlaceFollowOrderInstanceDTO;
import com.xy.api.model.request.order.PFOInstanceRequest;
import com.xy.api.model.request.order.PFOProductRequest;
import com.xy.api.model.request.order.SavePFOInstanceRequest;
import com.xy.api.model.request.order.SelectPFOInstanceRequest;
import com.xy.api.model.response.R;
import com.xy.api.model.response.Rows;
import com.xy.api.service.order.IPlaceFollowOrderInstanceService;
import com.xy.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/placeFollowOrder/instance")
public class PFOInstanceController extends BaseController {

    @Autowired
    private IPlaceFollowOrderInstanceService placeFollowOrderInstanceService;

    @PostMapping("/queryList")
    public R queryPFOInstanceList(@RequestBody PFOInstanceRequest request) {
        Rows<PlaceFollowOrderInstanceDTO> rows = placeFollowOrderInstanceService.queryPFOInstanceList(request);
        return success(rows);
    }

    @PostMapping("/delete")
    public R deletePFOInstance(@RequestBody PlaceFollowOrderInstanceDTO request) {
        placeFollowOrderInstanceService.deletePFOInstance(request.getId());
        return success();
    }

    @PostMapping("/save")
    public R savePFOInstance(@RequestBody SavePFOInstanceRequest request) {
        placeFollowOrderInstanceService.savePFOInstance(request);
        return success();
    }

    @PostMapping("/select")
    public R selectPFOInstance(@RequestBody SelectPFOInstanceRequest request) {
        List<PlaceFollowOrderInstanceDTO> instanceList = placeFollowOrderInstanceService.selectPFOInstance(request);
        return success(instanceList);
    }

    @PostMapping("/queryProductTree")
    public R queryProductTree(@RequestBody PFOProductRequest request) {
        List<ProductTreeNodeDTO> productTree = placeFollowOrderInstanceService.queryProductTree(request);
        return success(productTree);
    }

}
